<!--
 * @Author: your name
 * @Date: 2019-10-28 17:19:36
 * @LastEditTime: 2019-10-28 21:17:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \1026作业\1026.html
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <script>
        function longestCommonPrefix(arr) {
            let str = "";
            for (let i = 0; i < arr[0].length; i++) {
                let temp = arr[0][i];
                for (let j = 1; j < arr.length; j++) {
                    if (arr[j][i] == temp) {
                        continue;
                    } else {
                        return str;
                    }
                }
                str += temp;
            }
            return str;

        }
        console.log(longestCommonPrefix(["flower", "flow", "flight"]));



        //中位数
        function findMedianSortedArrays(arr1, arr2) {
            let arr = [];
            arr = arr.concat(arr1, arr2);
            arr.sort(function(a, b) {
                if (a > b) {
                    return 1;
                } else if (a == b) {
                    return 0;
                } else {
                    return -1;
                }
            });
            if (arr.length % 2 != 0) {
                return arr[Math.floor(arr.length / 2)];
            } else {
                return (arr[(arr.length / 2) - 1] + arr[(arr.length / 2)]) / 2;
            }

        }
        console.log(findMedianSortedArrays([1, 2, 6], [3, 4]));
    </script>
</body>

</html>